// packageE/membertool/membertool.js
const app = getApp();
Component({
  properties: {
    datas: {
      type: null,
    },
    component_id: {
      type: null,
    }
  },
  // 私有数据，可用于模板渲染
  data: {
    emptyImage:  `${app.globalData.imgPath}image.png`,
    activeNames: true,
  },
  lifetimes: {
    // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
    attached() {},
    moved() {},
    detached() {},
  },

  // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
  attached() {},
  // 此处attached的声明会被lifetimes字段中的声明覆盖
  ready() {},

  methods: {
    errorFunction(event) {
      let index = event.currentTarget.dataset.index;
      let img = 'datas.show_list[' + index + '].image';
      this.setData({
        [img]: `${app.globalData.imgPath}image.png`,
      });
    }, 
    //根据后台返回名字做跳转
    pluginGoto(e) {
      let item = e.currentTarget.dataset.item;
      let url = item.url;
      //跳转到推广中心
      if (item.url == "extension") {
        this.goextension();
        return;
      }

      if (item.name == "courier") {
        wx.setStorage({
          key: "couriername",
          data: item.title,
        });
        wx.navigateTo({
          url: "/packageA/member/" + url + "/" + url,
        });
      } else if (item.name == "supplier") {
        let uid = wx.getStorageSync('yz_uid')||0;
        wx.navigateTo({
          url: "/packageA/member/" + url + "/" + url + "?uid=" + uid
        });
      } else if (item.url == "HotelManage") {
        wx.navigateTo({
          url:
            "/packageA/hotel/HotelManage/HotelManage?title=" +
            encodeURIComponent("酒店管理"),
        });
      } else if (item.url == "aftersaleslist") {
        this.goaftersaleslist();
      } else if (item.url == "helperLiveList") {
        this.getTemplate();
      } else if (item.name == "m-erweima" && item.mini_url == "m-erweima" ) {
        this.triggerEvent("openQrCode", "block");
      } else if (item.url == "collageIndex") {
        wx.navigateTo({
          url: "/packageE/member/collage/collageIndex/collageIndex",
        });
      }else {
        let mini_url = item.mini_url;
        if(item.page_data && item.page_data.data_url) {
          mini_url = mini_url + `?api=${item.page_data.data_url}`;
        }
        if(item.page_data && item.page_data.date_time) {
          mini_url = mini_url + `&date_time=1`;
        }
        if(item.page_data && item.page_data.extparams) {
          mini_url = mini_url + `&extparams=${ JSON.stringify(item.page_data.extparams)}` 
        }
        if(item.page_data && item.page_data.plu) {
          mini_url = mini_url + `${item.page_data.data_url ? '&' : '?'}plu=${item.page_data.plu}`;
        }
        if(item.page_data && item.page_data.id) {
          mini_url = mini_url + `?id=${item.page_data.id}`;
        }
        wx.navigateTo({
          url: mini_url
        });
      }

    },
    goaftersaleslist: function () {
      wx.navigateTo({
        url: "/packageD/member/myOrder/Aftersaleslist/Aftersaleslist",
      });
    },

    goextension: function () {
      //extension
      wx.reLaunch({
        url: "/packageG/pages/member/extension/extension",
      });
    },
    onChange(event) {
      this.setData({
        activeNames: !this.data.activeNames,
      });
    },
    gotoUrl(e) {
      let url = e.currentTarget.dataset.item.h5_link;
      try {
        wx.navigateTo({
          url: url,
        });
      } catch (e) {
        wx.showToast({
          title: "链接设置错误",
          icon: "none",
          duration: 2000,
        });
      }
    },
  },
});
